<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "300px",
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");

      this.chart.setOption({
        color: ["#cd4692", "#9658c3", "#6c6be2", "#01aebf", "#18b794"],

        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        // legend: {
        //   left: "center",
        //   bottom: "10",
        //   data: ["Industries", "Technology", "Forex", "Gold", "Forecasts"],
        // },
        series: [
          {
            name: "告警",
            type: "pie",
            roseType: "radius",
            radius: [15, 120],
            center: ["50%", "50%"],
            data: [
              { value: 320, name: "人员出区域" },
              { value: 240, name: "人员进区域" },
              { value: 149, name: "车辆出区域" },
              { value: 100, name: "车辆进区域" },
              { value: 59, name: "满溢告警" },
            ],
            animationEasing: "cubicInOut",
            animationDuration: 1500,
            label: {
              show: false,
            },
          },
        ],
      });
    },
  },
};
</script>
